package donkeykong;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JPanel;

public class Sueloespecial extends JPanel{

	/**
	 * Color 0 232 216
	 */
	private static final long serialVersionUID = 1L;
	private Image imagen;
	private int posicion_x;
	private int posicion_y;
	private static Clip clickClip;
	private static AudioInputStream musicaFondo;
	
	public Sueloespecial(int posx, int posy) throws IOException {
		
		this.posicion_x=posx;
		this.posicion_y=posy;
		imagen = ImageIO.read(new File("./images/plataforma.png"));
	
}
	public int getPosicion_y() {
		// TODO Auto-generated method stub
		return this.posicion_y;
	}

	public int getPosicion_x() {
		// TODO Auto-generated method stub
		return this.posicion_x;
	}
	
	public void setPosicion_y(int posy) {
		// TODO Auto-generated method stub
		this.posicion_y=posy;
	}
	public void setPosicion_x(int posx) {
		// TODO Auto-generated method stub
		this.posicion_x=posx;
	}
	
	public void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		
		
		AffineTransform at = new AffineTransform();
	
		at.translate(getPosicion_x(), getPosicion_y()-imagen.getHeight(null));
		
		
		g2d.drawImage(imagen, at,  null);
		
	
}
	/** Funcion para escuchar la musica de fondo del nivel **/
	public static void escucharMusicaFondo(String sonido, int duracion){
		try {
			clickClip = AudioSystem.getClip();
			musicaFondo = AudioSystem.getAudioInputStream(new File("./sounds/"+sonido+".wav"));
			clickClip.open(musicaFondo);
			clickClip.loop(duracion);
			clickClip.start();
		} catch (LineUnavailableException e) {
			e.printStackTrace();
		} catch (UnsupportedAudioFileException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
